from OpenGL.GL import *
from OpenGL.GLUT import *

import sys
import math

points = [ map(float, l.split()) for l in file("triangles.poi") ]
strip = [1,2,3,4,5,6,7,6,8,9,8,10,11,12,13,14]

def initGL(width, height):
	# Set background color to red
	glClearColor(1.0, 0.0, 0.0, 0.0)
	# Set orthograpic projection
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	glOrtho(-1.5, 1.5, -1.5, 1.5, -1.0, 1.0)
	glMatrixMode(GL_MODELVIEW)
	
def display():
	# Clear framebuffer
	glClear(GL_COLOR_BUFFER_BIT)
	# Set color to light gray
	glColor3f(.75, .75, .75)
	# Set drawstyle
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
	# Set primitive type to polygon
	glBegin(GL_TRIANGLE_STRIP)
	drawVertex()
	glEnd()
	# Flush commands
	glFlush()
	
	
def drawVertex():
	for i in strip:
		glVertex2f(points[i-1][0], points[i-1][1])
		
def main():
	# Initialize GLUT
	glutInit(sys.argv)
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
	glutInitWindowSize(500, 500)
	glutCreateWindow("OpenGL TriangleStrip Riedelinho")
	# Register display callback function
	glutDisplayFunc(display)
	# Initialize OpenGL context
	initGL(500, 500)
	# Start GLUT mainloop
	glutMainLoop()
	
if __name__ == "__main__":
	main()